#!/bin/bash
# 获取所有贡献者列表
echo "["
authors=$(git log --format='%aN' | sort -u)
first=true
for author in $authors; do
    if [ "$first" = false ]; then
        echo ","
    fi
    echo "{"
    echo "\"name\":\"$author\","
    # 统计提交次数
    commit_count=$(git log --author="$author" --pretty=oneline | wc -l)
    echo "\"commits_count\":\"$commit_count\","
    # 统计新增和删除行数
    line_stat=$(git log --numstat --pretty="%aN" --author="$author" | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("%d %d", plus, minus)}')
    IFS=' ' read -ra stats <<< "$line_stat"
    echo "\"addRow\":\"${stats[0]}\","
    echo "\"delRow\":\"${stats[1]}\""
    echo "}"
    first=false
done
echo "]"